 %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% Sajad Saeedi
% University of New Brunswick
% Copy Right 2012
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
% ref: 
% S. Saeedi, L. Paull, M. Trentini, M. Seto, and H. Li, 
% Map Merging Using Hough Peak Matching, 
% Proceedings of the IEEE/RSJ International Conference on 
% Intelligent Robots and Systems (IROS), 
% Vilamoura, Portugal, October 7-12, pp. 4683 - 4688.
%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
function [im_occ1, im_occ2, im_occ2_rot, R1, T1, D1, R2, T2, D2, R2_rot, T2_rot, D2_rot, delta_ang] = adjust_radon(im1, im2)

% for map1
im_occ1 = pgm2occ(im1);         % Convert map 转换地图，以127为界(0,-1] 0 (0,1]
map1 = get_just_occ(im_occ1);   % extract occupied cells 提取出占据的栅格坐标
[ang1 R1 T1 D1] = align_roden(map1);        % apply Radon
ang1
%figure; imshow(map1, [-1,1]);   % show results
%set(gcf,'name','map_1','numbertitle','off');
%title('map_1', 'FontSize',12);

% for map2
im_occ2 = pgm2occ(im2);         % Convert map
map2 = get_just_occ(im_occ2);   % extract occupied cells
[ang2 R2 T2 D2] = align_roden(map2);        % apply Radon
ang2
%figure; imshow(map2, [-1,1]);  % show results

% get angle difference and align maps' orientation
delta_ang = ang2 - ang1
%delta_ang = 5.5;  % for Andrew's

%im_occ2_rot = map_transform(im_occ2, delta_ang, fix([-3 13]));
im_occ2_rot = map_transform(im_occ2, delta_ang, fix([0 0]));
%figure; imshow(im_occ2_rot, [-1,1]);  % show results

map2_rot = get_just_occ(im_occ2_rot);  
[ang2_rot R2_rot T2_rot D2_rot] = align_roden(map2_rot);
ang2_rot
%figure; imshow(map2_rot, [-1,1]);  % show results
%set(gcf,'name','map_2 rot','numbertitle','off');
%title('map_2 rot', 'FontSize',12);

end